/**
 * 给定1000个case，每个case4张牌，问能否算24，允许分数
 * 多case，无论如何用一个哈希做记忆化。对4张牌排个序。
 * 然后做一个全排列，对每个全排列去check一下能不能算出24。
 * 假设当前排列四张牌记作1234，则一共只有2大种模式：
 * (1 o 2) o 3 o 4
 * (1 o 2) o (3 o 4)
 * 其中o表示四种算符之一。如果是减法与除法，还需要交换。
 * 注意除法不能除零。
 * 这里用了一个dfs来处理依次计算的情况，也没有简单多少。还是直接写循环比较容易调试。
 */
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace std;

using llt = long long;
using vi = vector<int>;
using vll = vector<llt>;
using pii = pair<int, int>;
using pll = pair<llt, llt>;

struct _t{
    int fenzi;
    int fenmu;
    _t():fenzi(0),fenmu(1){}
    _t(int a, int b):fenzi(a),fenmu(b){
        if(b < 0) fenzi = -fenzi, fenmu = -fenmu;
        auto g = __gcd(abs(a), abs(b));
        fenzi /= g;
        fenmu /= g;
    }
    const _t operator + (const _t & r) const {
        return _t(fenzi * r.fenmu + fenmu * r.fenzi, fenmu * r.fenmu);
    }
    const _t operator - (const _t & r) const {
        return _t(fenzi * r.fenmu - fenmu * r.fenzi, fenmu * r.fenmu);
    }
    const _t operator * (const _t & r) const {
        return _t(fenzi * r.fenzi, fenmu * r.fenmu);
    }
    const _t operator / (const _t & r) const {
        return _t(fenzi * r.fenmu, fenmu * r.fenzi);
    }
    bool isOK() const {
        return 24 == fenzi and 1 == fenmu;
    }
    bool is0() const {
        return 0 == fenzi;
    }
    void disp() const {
        if(1 == fenmu) cout << fenzi;
        else cout << fenzi << " / " << fenmu;
    }
};

using fun_t = function<_t(const _t &, const _t &)>;
fun_t F[4] = {
    [](const _t & a, const _t & b){return a + b;},
    [](const _t & a, const _t & b){return a - b;},
    [](const _t & a, const _t & b){return a * b;},
    [](const _t & a, const _t & b){return a / b;},
};
const string S = "+-*/";

array<int, 4> A;
unordered_map<array<int, 4>, int, function<size_t(const array<int, 4> &)>, function<bool(const array<int, 4> &, const array<int, 4> &)>> Map(
    100,
    [](const array<int, 4> & a)->size_t{return (((a[0] * 1331 + a[1]) * 13313) + a[2]) * 13313 + a[3];},
    [](const array<int, 4> & a, const array<int, 4> & b)->bool{return a[0] == b[0] and a[1] == b[1] and a[2] == b[2] and a[3] == b[3];}
);

bool dfs(const vector<_t> & vec){
    if(vec.size() == 1){
        return vec[0].isOK();
    }

    vector<_t> v(vec.begin(), vec.end());
    auto b = v.back(); v.pop_back();
    auto a = v.back(); v.pop_back();
    v.push_back(F[0](a, b));
    bool flag = dfs(v);
    v.pop_back();
    if(flag) return true;

    v.push_back(F[1](a, b));
    flag = dfs(v);
    v.pop_back();
    if(flag) return true;    

    v.push_back(F[1](b, a));
    flag = dfs(v);
    v.pop_back();
    if(flag) return true;        

    v.push_back(F[2](a, b));
    flag = dfs(v);
    v.pop_back();
    if(flag) return true;      

    if(not b.is0()){
        v.push_back(F[3](a, b));
        flag = dfs(v);
        v.pop_back();
        if(flag) return true;            
    }  

    if(not a.is0()){
        v.push_back(F[3](b, a));
        flag = dfs(v);
        v.pop_back();
        if(flag) return true;            
    }      

    return false;
}

bool check(){
    bool flag = dfs(vector<_t>{{A[0], 1}, {A[1], 1}, {A[2], 1}, {A[3], 1}});
    if(flag) return true;

    for(int i=0;i<4;++i){
        auto t0 = F[i]({A[0], 1}, {A[1], 1});
        for(int j=0;j<4;++j){
            auto t2 = F[j]({A[2], 1}, {A[3], 1});
            bool flag = dfs(vector<_t>{t0, t2});
            if(flag) return true;

            if(j & 1){
                t2 = F[j]({A[3], 1}, {A[2], 1});
                bool flag = dfs(vector<_t>{t0, t2});
                if(flag) return true;
            }
        }
        if(i & 1){
            t0 = F[i]({A[1], 1}, {A[0], 1});
            for(int j=0;j<4;++j){
                auto t2 = F[j]({A[2], 1}, {A[3], 1});
                bool flag = dfs(vector<_t>{t0, t2});
                if(flag) return true;

                if(j & 1){
                    t2 = F[j]({A[3], 1}, {A[2], 1});
                    bool flag = dfs(vector<_t>{t0, t2});
                    if(flag) return true;
                }
            }            
        }
    }     
    return false;
}

bool proc(){
    auto it = Map.find(A);
    if(it != Map.end()) return it->second;

    do{
        if(check()){
            Map.insert(it, {A, 1});
            return true;
        }
    }while(next_permutation(A.begin(), A.end()));
    Map.insert(it, {A, 0});
    return false;
}

int TR[256] = {0};

void work(){
    for(auto & i : A) {
        string s; cin >> s;
        if(s.length() == 1) i = TR[s[0]];
        else i = 10;
    }
    sort(A.begin(), A.end());
    cout << (proc() ? "YES\n" : "NO\n");
    return;
}


int main(){
#ifndef ONLINE_JUDGE
    freopen("z.txt", "r", stdin);
#endif
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);	
    for(int c='0';c<='9';++c)TR[c] = c - '0';
    TR['A'] = 1;
    TR['K'] = 13;
    TR['Q'] = 12;
    TR['J'] = 11;
    
    int nofkase = 1;
	cin >> nofkase;
	while(nofkase--) work();
	return 0;
}